﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfClient
{
    /// <summary>
    /// Window1.xaml 的交互逻辑
    /// </summary>
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();

            this.MouseDown += (w, args) => MessageBox.Show("ddd  " + args.GetPosition(w as Window), (w as Window).Title);

            //this.Background = brush;
        }

        public static char[] WhitespaceChars = new char[] { 
        '\t', '\n', '\v', '\f', '\r', ' ', '\x0085', '\x00a0', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 
        ' ', ' ', ' ', ' ', '​', '\u2028', '\u2029', '　', '﻿'
     };

        public static readonly RoutedCommand SelectFocusCommand = new RoutedCommand("SelectFocus", typeof(Window1));

        public class NoFocusHyperlink : Hyperlink
        {
            protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e)
            {
                this.OnClick();
            }

            protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
            {
                e.Handled = true;
            }
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            //textBox1.Text = TrimAll(textBox1.Text);
        }

        public static string TrimAll(string s)
        {
            if (s == null || s.Length == 0)
                return s;
            string r = s.Trim();

            string ret = "";

            int startIndex = 0;
            while (startIndex < r.Length)
            {
                int index = 0;
                char ch = r[startIndex];
                index = 0;
                while (index < WhitespaceChars.Length)
                {
                    if (WhitespaceChars[index] == ch)
                    {
                        break;
                    }
                    index++;
                }
                if (index == WhitespaceChars.Length)
                {
                    //continue;
                    ret += ch;
                }
                startIndex++;
                
            }
            return ret;
        }

        protected override void OnTextInput(TextCompositionEventArgs e)
        {
            base.OnTextInput(e);
            
        }

        //SolidColorBrush brush = new SolidColorBrush(Colors.Black);
        //protected override void OnMouseMove(MouseEventArgs e)
        //{
        //    base.OnMouseMove(e);

        //    double width = this.ActualWidth - 2 * SystemParameters.ResizeFrameHorizontalBorderHeight;
        //    double height = this.ActualHeight - 2 * SystemParameters.ResizeFrameVerticalBorderWidth - SystemParameters.CaptionHeight;

        //    Point ptMouse = e.GetPosition(this);
        //    Point ptCenter = new Point(width / 2, height / 2);

        //    Vector vectorMouse = ptMouse - ptCenter;
        //    double angle = Math.Atan2(vectorMouse.Y, vectorMouse.X);

        //    Vector vectorEllipse = new Vector(width / 2 * Math.Cos(angle), height / 2 * Math.Sin(angle));
        //    Byte level = (Byte)(255 * (1 - Math.Min(1, vectorMouse.Length / vectorEllipse.Length)));
        //    Color color = brush.Color;
        //    color.R = color.G = color.B = level;
        //    brush.Color = color;
        //}

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Window2 win = new Window2();
            win.Owner = this;
            //win.ShowInTaskbar = false;
            win.Show();

            GradientWindow gw = new GradientWindow();
            gw.Owner = this;
            gw.Show();

            

        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            ButtonDemoWindow win = new ButtonDemoWindow();
            win.Owner = this;
            //win.ShowInTaskbar = false;
            win.Show();
        }

        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            //WpfClient.Content.SimpleWindow win = new WpfClient.Content.SimpleWindow();
            WpfClient.Content.ImageWindow win = new WpfClient.Content.ImageWindow();
            win.Owner = this;
            win.ShowInTaskbar = false;
            win.Show();
        }

        private void Button_Click_3(object sender, RoutedEventArgs e)
        {
            WpfClient.Content.TextBoxWindow win = new WpfClient.Content.TextBoxWindow();
            win.Owner = this;
            win.ShowInTaskbar = false;
            win.Show();

        }

        private void Button_Click_4(object sender, RoutedEventArgs e)
        {
            WpfClient.Layout.StackPanleWindow win = new WpfClient.Layout.StackPanleWindow();
            win.Owner = this;
            win.ShowInTaskbar = false;
            win.Show();

            WpfClient.Layout.StackPanelXamlWindow win1 = new WpfClient.Layout.StackPanelXamlWindow();
            win1.Owner = this;
            win1.ShowInTaskbar = false;
            win1.Show();

            WpfClient.Layout.StackPanelWindow1 win2 = new WpfClient.Layout.StackPanelWindow1();
            win2.Owner = this;
            win2.ShowInTaskbar = false;
            win2.Show();

            // 
            WpfClient.Layout.WrapPanelWindow1 win3 = new WpfClient.Layout.WrapPanelWindow1();
            win3.Owner = this;
            win3.ShowInTaskbar = false;
            win3.Show();
            
        }

        
    }
}
